package com.crm.controller;


import com.crm.common.result.AjaxResult;
import com.crm.common.result.PageResult;
import com.crm.common.result.Result;
import com.crm.domain.Course;
import com.crm.dto.CourseDto;
import com.crm.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/clues/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    // 课程保存
    @PostMapping
    public AjaxResult save(@RequestBody Course course){
        log.info("开始课程保存：{}",course);
        courseService.saveCourse(course);
        return AjaxResult.success();
    }

    // 课程查询
    @GetMapping("{id}")
    public AjaxResult getById(@PathVariable Long id){
        log.info("开始课程查询：{}",id);
        Course course = courseService.getById(id);
        return AjaxResult.success(course);
    }

    //修改课程
    @PutMapping
    public AjaxResult updateCourse(@RequestBody Course course){
        log.info("开始课程修改：{}",course);
        courseService.updateCourse(course);
        return AjaxResult.success();
    }

    //根据ids删除课程
    @DeleteMapping("{ids}")
    public AjaxResult delete(@PathVariable List<Long> ids){
        log.info("开始课程删除：{}",ids);
        courseService.removeByIds(ids);
        return AjaxResult.success();
    }
    //课程列表查询
    @GetMapping("/list")
    public PageResult list(CourseDto courseDto){
        log.info("开始课程列表查询：{}",courseDto);
        return courseService.list(courseDto);
    }

    @GetMapping("/listselect")
    public AjaxResult listSelect(){
        List<Course> list = courseService.listSelect();
        return AjaxResult.success(list);
    }

}
